package com.saianfu.flowable.demo.controller

import com.saianfu.flowable.demo.common.impl.TaskHandler
import com.saianfu.flowable.demo.controller.result.ResponseData
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation

import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController
import springfox.documentation.annotations.ApiIgnore

/**
 *
 *
 * 任务处理人相关
 *
 */
@ApiIgnore
@RestController
@RequestMapping("api/flow/user")
@Api(value = "User", tags = ["任务处理人"])
class UserController {
    @Autowired
    lateinit var taskHandler: TaskHandler

    /**
     * 执行流程任务
     */
    @RequestMapping(value = ["/transferTask"], method = [RequestMethod.GET])
    @ResponseBody
    @ApiOperation(value = "任务移交", produces = "application/json")
    @ApiImplicitParams(ApiImplicitParam(name = "taskId", value = "任务ID", required = true, dataType = "String"), ApiImplicitParam(name = "userId", value = "用户ID（接受移交的用户）", required = true, dataType = "String"))
    @Throws(Exception::class)
    fun transferTask(taskId: String, userId: String): ResponseData<*> {
        taskHandler.setAssignee(taskId, userId)
        return ResponseData.success()
    }

    companion object {
        protected var logger = LoggerFactory.getLogger(UserController::class.java)
    }
}